﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Numerics;

//Write a program to calculate the Nth Catalan number by given N.

namespace _10CatalanNumbers
{
    class _10CatalanNumbers
    {
        static void Main(string[] args)
        {
            Console.WriteLine("Calculating the Nth Catalan number.");
            Console.Write("Enter value for N:");
            string strN = Console.ReadLine();
            BigInteger N = BigInteger.Parse(strN);
            BigInteger twoNFactorial = 1;
            BigInteger counterTwoN = 2 * N;
            while (counterTwoN > 0)
            {
                twoNFactorial = twoNFactorial * counterTwoN;
                counterTwoN--;
            }
            Console.WriteLine("(2n)! = " + twoNFactorial);
            BigInteger onePlusNFactorial = 1;
            BigInteger counterOnePlusN = N + 1;
            while(counterOnePlusN > 0)
            {
                onePlusNFactorial = onePlusNFactorial * counterOnePlusN;
                counterOnePlusN--;
            }
            Console.WriteLine("(N + 1)! = " + onePlusNFactorial);
            BigInteger nFactorial = 1;
            while (N > 0)
            {
                nFactorial = nFactorial * N;
                N--;
            }
            Console.WriteLine("N! = " + nFactorial);
            BigInteger divider = nFactorial * onePlusNFactorial;
            BigInteger result = twoNFactorial / divider;
            Console.WriteLine("The Nth Catalan number is " + result);
        }
    }
}
